package math;

public class Probability {
	public int probability(int n,int m,int x,double d) throws Exception {
		if(n>=m)
			throw new Exception("a must great than b");
		if(x<n||x>m)
			throw new Exception("x must great than n and m must great than x");
		if(d<0||d>1)
			throw new Exception("d must great than 0.0 and m must great than 1.0");
		double r = Math.random();
		if (r<=d) {
			return x;
		}else{
			int y = (int)(Math.random()*(m-n+1))+n;
			while(y==x){
				y = (int)(Math.random()*(m-n+1))+n;
			}
			return y;
		}
	}
}
